﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dict.aspx.cs" Inherits="admin_Dict" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="js/themes/gray/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/themes/icon.css" />
    <script type="text/javascript" src="../js/jquery-1.4.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Dt").datagrid({
                title: '字典列表',
                url: 'Operation.ashx?cmd=getDictList',
                height: parent.document.body.clientHeight - 110,
                method: "GET",
                rownumbers: true,
                singleSelect: true,
                pagination: true,
                columns: [[
	                { title: 'ID', field: 'ID', width: 100, hidden: true },
                    { title: '类别', field: 'TCODES', width: 200,
                        formatter: function (value, rowData, rowIndex) {
                            switch (value) {
                                case "description":
                                    return "网站描述";
                                case "keywords":
                                    return "网站关键字";
                                case "news":
                                    return "新闻类别";
                                case "products":
                                    return "产品类别";
                                case "title":
                                    return "网站标题";
                            }
                        }
                    },
                    { title: '名称', field: 'TNAME', width: 400 },
                    { title: '备注', field: 'TMEMO', width: 200 }
				]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        $("#CODES").combobox('enable');
                        $('#dlg').dialog('open').dialog('setTitle', '新类别');
                        $('#fm').form('clear');
                        editId = "-1";
                        url = 'Operation.ashx?cmd=saveDict';
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var row = $('#Dt').datagrid('getSelected');
                        if (row.TCODES == "description" || row.TCODES == "keywords" || row.TCODES == "title") {
                            $("#CODES").combobox('disable');
                        }
                        else {
                            $("#CODES").combobox('enable');
                        }
                        if (row) {
                            $('#dlg').dialog('open').dialog('setTitle', '修改类别');
                            $('#fm').form('load', row);
                            editId = row.ID;
                            type = row.TCODES;
                            url = 'Operation.ashx?cmd=updateDict&id=' + row.ID;
                        }
                        else {
                            $.messager.alert("提示信息", "请选择一行", "info");
                        }
                    }
                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var row = $('#Dt').datagrid('getSelected');
                        if (row.TCODES == "description" || row.TCODES == "keywords" || row.TCODES == "title") {
                            $.messager.alert("提示信息", "此类别不能删除", 'error');
                            return;
                        }
                        if (row) {
                            $.messager.confirm('提示信息', '你确定要删除所选定的数据吗?', function (r) {
                                if (r) {
                                    var row = $('#Dt').datagrid('getSelected');
                                    $.post("Operation.ashx?cmd=delDict", { delId: row.ID }, function (data, status) {
                                        var dd = eval("(" + data + ")")
                                        if (dd.success) {
                                            $("#Dt").datagrid("reload");
                                        }
                                        else {
                                            $.messager.alert("提示信息", dd.msg, 'error');
                                        }
                                    }, "text");
                                }
                            });
                        } else {
                            $.messager.alert("提示信息", "请选择一行", "info");
                        }
                    }
                }],
                onSelect: function (rowIndex, rowData) {
                    if (rowData.TCODES == "description" || rowData.TCODES == "keywords" || rowData.TCODES == "title") {
                        $("#CODES").combobox('disable');
                    } else {
                        $("#CODES").combobox('enable');
                    }
                    $('#dlg').dialog('open').dialog('setTitle', '修改类别');
                    $('#fm').form('load', rowData);
                    editId = rowData.ID;
                    type = rowData.TCODES;
                    url = 'Operation.ashx?cmd=updateDict&id=' + rowData.ID;
                }
            });
        });

        var url = "";
        var editId = "-1"
        var type = "";
        function saveUser() {
            $.post("Operation.ashx?cmd=checkDict", { n: encodeURIComponent($("#NAME").val()), id: editId, t: type }, function (data) {
                var result = eval("(" + data + ")");
                if (result.success) {
                    $.messager.alert('提示信息', result.msg, 'error');
                } else {
                    $('#fm').form('submit', {
                        url: url,
                        onSubmit: function () {
                            var check = $(this).form('validate');
                            return check;
                        },
                        success: function (data) {
                            var result = eval("(" + data + ")");
                            if (result.success) {
                                $('#dlg').dialog('close');
                                $('#Dt').datagrid('reload');
                            } else {
                                $.messager.alert('提示信息', result.msg, 'error');
                            }
                        }
                    });
                }
            }, "text");
        }
    </script>
</head>
<body>
    <table id="Dt" class="easyui-datagrid">
    </table>
    <div style="display: none;">
        <div id="dlg" class="easyui-dialog" style="width: 400px; height: 280px; padding: 10px 20px"
            closed="true" buttons="#dlg-buttons">
            <div style="font-size: 14px; font-weight: bold; color: #666; padding: 5px 0; margin-bottom: 10px;
                border-bottom: 1px solid #ccc;">
                类别信息</div>
            <form id="fm" method="post">
            <div style="height: 30px;">
                <label>
                    类别:</label>
                <select class="easyui-combobox" id="CODES" name="TCODES" panelheight="auto" required="true"
                    style="width: 152px;">
                    <option value="description">网站描述</option>
                    <option value="keywords">网站关键字</option>
                    <option value="title">网站标题</option>
                    <option value="news">新闻类别</option>
                    <option value="products">产品类别</option>
                </select>
            </div>
            <div style="height: 30px;">
                <label>
                    名称:</label>
                <input id="NAME" name="TNAME" class="easyui-validatebox txt" required="true" validtype="length[0,200]"
                    invalidmessage="输入字符不能超过200字符" style="width: 300px;" />
            </div>
            <div style="height: 30px;">
                <label>
                    备注:</label>
                <textarea name="TMEMO" class="txt" style="height: 80px; width: 300px;"></textarea>
            </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" onclick="saveUser()">保存</a> <a href="#" class="easyui-linkbutton"
                onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
    </div>
</body>
</html>
